import React, { Component } from 'react'
import { Router, Redirect, Route, Switch } from 'react-router-dom'

import './index.css'
import Layout from '@/pages/Layout'
import Login from '@/pages/Login'
import NotFound from '@/pages/NotFound'
import AuthRoute from './components/AuthRoute'
import history from './utils/history'

class App extends Component {
  render() {
    return (
      <Router history={history}>
        <div>
          <Switch>
            <Redirect exact from="/" to="/home"></Redirect>
            {/* <Route path="/home" component={Layout}></Route> */}
            {/* <Route
              path="/home"
              render={(props) => {
                if (hasToken()) {
                  //{...props}批量进行父传子，将props对象中的所有属性，都进行父传子
                  return <Layout {...props}></Layout>
                } else {
                  //跳转到登录页
                  return <Redirect to="/login"></Redirect>
                }
              }}
            ></Route> */}
            <AuthRoute path="/home" component={Layout}></AuthRoute>

            <Route path="/login" component={Login}></Route>
            <Route component={NotFound}></Route>
          </Switch>
        </div>
      </Router>
    )
  }
}

export default App
